/**
 *******************************************************************************
 * @file commun_queue.h
 * @author .ISS_AUTO (hudandan@issauto.com)
 * @date 2023-06-05  1. Base Version.
 *       2024-02-26  1. 新增函数 int comm_receive_bytes_length(unsigned char chan);
 *                                       2. 新增函数 int comm_transmit_bytes_length(unsigned char chan);
 *       2025-03-31  1. 优化返回参数
 *
 * @brief  This file for User Communication Interface.
 *
 * @copyright Copyright (c) 2023 ISSAUTO TECH Co., Ltd. All rights reserved.
 *
 *******************************************************************************
 */
/* Define to prevent recursive inclusion -------------------------------------*/

#ifndef __USER_COMMUN_QUEUE_H
#define __USER_COMMUN_QUEUE_H

#ifdef __cplusplus
extern "C" {
#endif

/* Exported Includes ---------------------------------------------------------*/
#include "uart_driver.h" //!< uart driver interface

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/*!< 默认通道对应 UART-RX/TX */
#define COMM_CHANNEL_MAX_NUM    UART_CHANNEL_MAX

/* Exported macro ------------------------------------------------------------*/
// #define rb_printf(M, ...)    USER_PRINTF(M, ##__VA_ARGS__)
#define rb_printf(M, ...)

/*!< RX/TX-RingQueue 使能配置 */
#define COMM_RING_QUEUE_RX    (1U)
#define COMM_RING_QUEUE_TX    (0U)

/* Exported functions --------------------------------------------------------*/
/**
 * @brief Clean commun ring queue
 *
 * @param[in] chan specified commun channel
 */
void Comm_RingQueue_Clear(unsigned char chan);

#if (0)
/**
 * @brief Delete commun ring queue
 *
 * @param[in] chan specified commun channel
 */
void Comm_RingQueue_Delete(unsigned char chan);

/**
 * @brief Initialize commun ring queue
 *
 * @param[in] chan specified commun channel
 *
 *        The following #defines should be used to configure Tx/Rx buffer sizes for all Commun. channels.
 *        This allows each buffer for each channel to be a configurable size for saving RAM.
 *        If a channel is not used, size must be at least 1 to compile.
 * @param[in] rx_size size of ring buffer
 * @param[in] tx_size size of ring buffer
 */
void Comm_RingQueue_Init(unsigned char chan, unsigned int rx_size, unsigned int tx_size);
#endif

/**
 * @brief Initialize commun ring queue
 *
 * @param[in] chan specified commun channel
 * @param[in] r_pBuffer ring rcv buffer
 * @param[in] rx_size   size of ring buffer
 * @param[in] t_pBuffer ring send buffer
 * @param[in] tx_size   size of ring buffer
 */
void Comm_RingQueue_Buff_Init(unsigned char chan,
                              unsigned char *r_pBuffer, unsigned int rx_size,
                              unsigned char *t_pBuffer, unsigned int tx_size);

#if defined(COMM_RING_QUEUE_RX) && (COMM_RING_QUEUE_RX)
unsigned int comm_receive_bytes_push(unsigned char chan, unsigned char *buf, unsigned int len);
unsigned int comm_receive_bytes_pop(unsigned char chan, unsigned char *buf, unsigned int len);
unsigned int comm_receive_bytes_length(unsigned char chan);
#endif
#if defined(COMM_RING_QUEUE_TX) && (COMM_RING_QUEUE_TX)
unsigned int comm_transmit_bytes_push(unsigned char chan, unsigned char *buf, unsigned int len);
unsigned int comm_transmit_bytes_pop(unsigned char chan, unsigned char *buf, unsigned int len);
unsigned int comm_transmit_bytes_length(unsigned char chan);
#endif

#ifdef __cplusplus
}
#endif

#endif /* __USER_COMMUN_QUEUE_H */

/* END OF FILE ---------------------------------------------------------------*/
